#pragma once
#include <list>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>

//typedef std::vector<double> Array1d;
#define FILE_TYPE_REF "***REF***"
typedef struct _REF_SEGMENT
{
	double f1{ 0 };
	double f2{ 0 };
	double df{ 0 };
	std::string val1;
	std::string slope;
	std::string val2;
	std::string alarm1;
	std::string alarm2;
	std::string abort1;
	std::string abort2;
} REF_SEGMENT;

struct REF_DATA
{
public:
	int nMatDiagIndex{ -1 };
	int nFFT{ 0 };
	std::string szName;
	std::list<REF_SEGMENT> listSegment;
	std::vector<double> vRef;
	std::vector<double> vAlarm1;
	std::vector<double> vAlarm2;
	std::vector<double> vAbort1;
	std::vector<double> vAbort2;
	std::vector<double> vf;
	REF_DATA() {}
	REF_DATA(int nLines)
	{
		nFFT = int(nLines*2.56);
		vf.resize(nFFT / 2 + 1, 0);
		vRef.resize(nFFT / 2 + 1, 0);
		vAlarm1.resize(nFFT / 2 + 1, 0);
		vAlarm2.resize(nFFT / 2 + 1, 0);
		vAbort1.resize(nFFT / 2 + 1, 0);
		vAbort2.resize(nFFT / 2 + 1, 0);
	}
	virtual void ResetVector();
	void CalOverallCoh();
	void CalOverallPhi();
	void WriteFile(const std::string& szFile);
	void ReadFile(const std::string& szFile);
};
typedef REF_DATA REF_COH;
typedef REF_DATA REF_PHI;
typedef REF_DATA REF_CSD;

struct REF_PSD : public REF_DATA
{
public:
	// belows are only available for PSD
	double dRMS{ 0 };
	double dMaxAcc{ 0 };
	double dMaxVel{ 0 };
	double dMaxDisp{ 0 };
	REF_PSD() {}
	REF_PSD(int nLines) :REF_DATA(nLines) {}
	void CalOverallPSD();
	void RescaleRMS(double newRMS);
};
enum REF_TYPE { PSD = 0, COH, PHI };

std::ostream& operator << (std::ostream& os, const REF_DATA& Ref);
std::istream& operator >> (std::istream& is, REF_DATA& Ref);
